package com.lrkj.payfee.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.lrkj.common.utils.DateUtils;
import com.lrkj.payfee.domain.RuleCost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lrkj.payfee.mapper.ModePaymentMapper;
import com.lrkj.payfee.domain.ModePayment;
import com.lrkj.payfee.service.IModePaymentService;

/**
 * 收款方式Service业务层处理
 *
 * @author yajun_ren
 * @date 2021-08-06
 */
@Service
public class ModePaymentServiceImpl implements IModePaymentService
{
    @Autowired
    private ModePaymentMapper modePaymentMapper;

    /**
     * 查询收款方式
     *
     * @param modePaymentId 收款方式ID
     * @return 收款方式
     */
    @Override
    public ModePayment selectModePaymentById(String modePaymentId)
    {
        return modePaymentMapper.selectModePaymentById(modePaymentId);
    }

    /**
     * 查询收款方式列表
     *
     * @param modePayment 收款方式
     * @return 收款方式
     */
    @Override
    public List<ModePayment> selectModePaymentList(ModePayment modePayment)
    {
        return modePaymentMapper.selectModePaymentList(modePayment);
    }

    /**
     * 新增收款方式
     *
     * @param modePayment 收款方式
     * @return 结果
     */
    @Override
    public int insertModePayment(ModePayment modePayment)
    {
        modePayment.setCreateTime(DateUtils.getNowDate());
        return modePaymentMapper.insertModePayment(modePayment);
    }

    /**
     * 修改收款方式
     *
     * @param modePayment 收款方式
     * @return 结果
     */
    @Override
    public int updateModePayment(ModePayment modePayment)
    {
        modePayment.setUpdateTime(DateUtils.getNowDate());
        return modePaymentMapper.updateModePayment(modePayment);
    }

    /**
     * 批量删除收款方式
     *
     * @param modePaymentIds 需要删除的收款方式ID
     * @return 结果
     */
    @Override
    public int deleteModePaymentByIds(String[] modePaymentIds)
    {
        return modePaymentMapper.deleteModePaymentByIds(modePaymentIds);
    }

    /**
     * 删除收款方式信息
     *
     * @param modePaymentId 收款方式ID
     * @return 结果
     */
    @Override
    public int deleteModePaymentById(String modePaymentId)
    {
        return modePaymentMapper.deleteModePaymentById(modePaymentId);
    }

    @Override
    public int doSaveList(List<ModePayment> batchBean) {
        List<ModePayment> saveBeans = new ArrayList<>();
        if (batchBean.size() > 500) {
            for (int i = 0; i < batchBean.size(); i++) {
                if ((i + 1) % 500 == 0) {
                    saveBeans.add(batchBean.get(i));
                    modePaymentMapper.doSaveList(saveBeans);
                    saveBeans.clear();
                } else {
                    saveBeans.add(batchBean.get(i));
                }
            }
            if (null != saveBeans && saveBeans.size() > 0) {
                modePaymentMapper.doSaveList(saveBeans);
            }
        } else {
            if (batchBean.size() > 0) {
                modePaymentMapper.doSaveList(batchBean);
            }
        }
        return 1;
    }
}
